package com.aboat.model;

import com.aboat.view.WindowFrame;

/**
 * @author
 * @email clear_windy@yeah.net
 * @create 2017-04-16 19:39
 */
public class RunCraet extends Thread implements Runnable{

    public void run() {

        WindowFrame.crawler = new ImageCrawler(WindowFrame.textStoragePath.getText()+"/log", WindowFrame.textStoragePath.getText()+"/picture");//日志路径，抓取内容路径
        try {
            for(String str : WindowFrame.seedList){
                WindowFrame.crawler.addSeed(str);
            }
            for(String str : WindowFrame.regularList){
                WindowFrame.crawler.addRegex(str);
            }
            WindowFrame.crawler.setImgTag(WindowFrame.tagField.getText());
            WindowFrame.crawler.setThreads(WindowFrame.threadSlider.getValue());
            WindowFrame.crawler.setResumable(true);//断点爬取
            WindowFrame.textContent.append("开始爬取..."+"\r\n");
            WindowFrame.crawler.start(WindowFrame.depthSlider.getValue());

            /*爬虫开始阻塞*/
            while(WindowFrame.crawler.isResumable()){}

            WindowFrame.textContent.append("爬取结束"+"\r\n");
            WindowFrame.textContent.selectAll();
            WindowFrame.actionButton.setEnabled(true);
        }catch(Exception ex){
            WindowFrame.textContent.append(ex.getMessage()+"\r\n");
            WindowFrame.textContent.selectAll();
        }
    }
}
